<template>
    <el-container>
        <el-header>
            <div class="left-panel">
                <el-button type="primary" icon="el-icon-plus" v-show="orgType==2" :disabled="!addState" @click="opAdd">新增</el-button>
            </div>
            <div class="right-panel">
                <el-button :icon="Search"   type="primary" @click="opBindData">查询</el-button>
                <el-button :icon="Search" type="info" plain @click="resetSearch">重置</el-button>
                <el-button text type="primary" @click="showCondition = !showCondition">
                    <span v-if="!showCondition">展开</span>
                    <span v-else>收起</span>
                    <vab-icon
                        class="vab-dropdown"
                        :class="{ 'vab-dropdown-active': fold }"
                        icon="arrow-up-s-line"
                    />
                </el-button>
            </div>
        </el-header>
        <el-foot v-show="showCondition">
            <vab-query-form-top-panel>
                <el-form inline label-width="49px" :model="queryForm" style="margin-top: 5px">
                    <el-form-item label="申请编号" label-width="100px">
                        <el-input
                            placeholder="---请输入申请编号---"
                            v-model="queryList.afterOrderCode"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="申请单位" label-width="100px">
                        <el-input
                            placeholder="---请输入申请单位---"
                            v-model="queryList.storeName"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="要货编号" label-width="100px">
                        <el-input
                            placeholder="---请输入要货编号---"
                            v-model="queryList.applyOrderCode"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="申请类型" label-width="100px">
                        <el-select
                            placeholder="---请选择申请类型---"
                            v-model="queryList.afterOrderType"
                            style="width: 300px"
                        >
                            <el-option label="---请选择---" value />
                            <el-option
                                v-for="item in optionsAfterOrderType"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                    <el-form-item label="状态" label-width="100px">
                        <el-select
                            placeholder="---请选择状态---"
                            v-model="queryList.status"
                            style="width: 300px"
                        >
                            <el-option label="---请选择---" value />
                            <el-option
                                v-for="item in optionsStatus"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                    <el-form-item label="供应商" label-width="100px">
                        <el-input
                            placeholder="---请输入供应商---"
                            v-model="queryList.supplierName"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="申请人" label-width="100px">
                        <el-input
                            placeholder="---请输入申请人---"
                            v-model="queryList.createName"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="申请时间" label-width="100px">
                        <el-date-picker
                            style="width: 300px"
                            v-model="queryList.dates"
                            type="datetimerange"
                            value-format="YYYY-MM-DD HH:mm:ss"
                            format="YYYY-MM-DD HH:mm:ss"
                            range-separator="-"
                            unlink-panels="true"
                            start-placeholder="开始时间"
                            end-placeholder="结束时间"
                            :default-time="defaultTime"
                        />
                    </el-form-item>
                    <el-form-item label="备注" label-width="100px">
                        <el-input
                            placeholder="---请输入备注---"
                            v-model="queryList.remarks"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="物料简码" label-width="100px">
                        <el-input
                            placeholder="---请输入物料简码---"
                            v-model="queryList.materialSimpCode"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="物料编码" label-width="100px">
                        <el-input
                            placeholder="---请输入物料编码---"
                            v-model="queryList.materialCode"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="物料分类" label-width="100px">
                       
                        <el-tree-select
                        placeholder="---请选择物料分类---"
                            v-model="queryList.materialTypeIds"
                            :props="{ label: 'label', value:'value',children: 'children' }"
                            :data="materialTypeTree"
                            multiple
                            :render-after-expand="false"
                            show-checkbox
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="物料名称" label-width="100px">
                        <el-input
                            placeholder="---请输入物料名称---"
                            v-model="queryList.materialName"
                            style="width: 300px"
                        />
                    </el-form-item>
                </el-form>
            </vab-query-form-top-panel>
        </el-foot>
        <!-- 供应商 -->
        <el-main class="nopadding">
            <scTable
                ref="mytable"
                :queryType="'after-order/item-pages'"
                :data="listData"
                :queryList="queryList"
                :column="columnList"
                :orderList="OrderList"
                :sort-orders="['ascending', 'descending']"
                @selection-change="selectionChange"
                row-key="StoreId"
                key="StoreId"
                stripe
                show-summary
                remoteSummary
            >
                <el-table-column type="selection" width="50"></el-table-column>
                <el-table-column prop="afterOrderTime" label="下单时间" width="170" sortable></el-table-column>
                <el-table-column prop="storeFullName" label="申请单位" width="280" sortable></el-table-column>
                <el-table-column prop="afterOrderCode" label="申请编号" width="150" sortable></el-table-column>
                <el-table-column prop="materialCode" label="物料编码" width="120" sortable></el-table-column>
                <el-table-column prop="materialName" label="物料名称" width="220" sortable></el-table-column>
                <el-table-column prop="unitName" label="单位" width="100" sortable></el-table-column>
                <el-table-column prop="qty" label="申请数量" width="100" ></el-table-column>
                <el-table-column prop="qty" label="实际接单数量" width="150">
                    <template #default="scope">
                        <span>--</span>
                    </template>
                </el-table-column>
                <el-table-column prop="price" label="单价" width="100" sortable></el-table-column>
                <el-table-column prop="totalAmount" label="总额" width="100" sortable>
                    <template #default="scope">
                        <span>{{scope.row.qty*scope.row.price}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="afterOrderTypeDesc" label="申请类型" width="120" sortable></el-table-column>
                <el-table-column prop="supplierFullName" label="供应商名称" width="240" sortable show-overflow-tooltip></el-table-column>
                <el-table-column prop="applyOrderCode" label="门店要货编号" width="200" sortable></el-table-column>
                <el-table-column prop="createName" label="申请人" width="120" sortable></el-table-column>
                <el-table-column prop="statusDesc" label="状态" width="120" sortable></el-table-column>
                <el-table-column prop="remarks" label="退货出库提醒" width="150" sortable></el-table-column>
                <el-table-column label="操作" fixed="right" align="right" width="250">
                    <template #default="scope">
                        <el-button-group>
                            <el-button text  type="primary" size="small" @click="opShow(scope.row, scope.$index)">查看</el-button>
                            <el-button text type="primary" size="small"  @click="opEdit(scope.row, scope.$index)" v-if="scope.row.status==2 || scope.row.status==3 || scope.row.status==4 ||scope.row.status==5">编辑</el-button>
                            <el-popconfirm title="确定撤回吗？"  @confirm="opState(scope.row, 5)" v-if="scope.row.status==0">
                                <template #reference>
                                    <el-button  text type="danger"  size="small">撤回</el-button>
                                </template>
                            </el-popconfirm>
                            <el-popconfirm title="确定终止吗？"  @confirm="opState(scope.row,6)" v-if="scope.row.status==2 || scope.row.status==3 || scope.row.status==4 || scope.row.status==5">
                                <template #reference>
                                    <el-button  text type="danger"  size="small">终止</el-button>
                                </template>
                            </el-popconfirm>
                        </el-button-group>
                    </template>
                </el-table-column>
            </scTable>
        </el-main>
    </el-container>

    <save-dialog
        v-if="dialogSave"
        ref="saveDialog"
        @fatherMethod="opBindData"
        @success="handleSaveSuccess"
        @closed="dialogSave = false"
    ></save-dialog>
    <detail-dialog
        v-if="dialogDetail"
        ref="detailDialog"
        @fatherMethod="opBindData"
        @success="handleSaveSuccess"
        @closed="dialogDetail = false"
    ></detail-dialog>
    
</template>

<script>

import detailDialog from "./detail";
import publicjs from "@/api/model/publicjs";
import tool from "@/utils/tool";
import config from "@/config";
export default {
    name: "posInfo-room",
    components: {
        detailDialog,
        publicjs,
    },
    data() {
        return {
           
            dialogDetail: false,
           
            showCondition: false,
            selectionRows: [],
            pkList: ["StoreId"],
            columnList: [],
            OrderList: { StoreId: "Asc" },
            queryList: {
            },
            result: "", // 运行结果
            props1: {
                checkStrictly: true,
                emitPath: false,
            },
            orgCodeList: "",
            orgNameList: "",
            addState: true, //可以增加
            editState: true, //可以修改
            editBatchState: true, //可以批量修改
            deleteState: true, //可以删除
			optionsStatus:[],//状态
            optionsAfterOrderType:[],//申请类型
            materialTypeTree:[],
            orgType:1,
            defaultTime:[
                new Date(2000, 1, 1, 0, 0, 0),
                new Date(2000, 2, 1, 23, 59, 59),
            ]
        };
    },
    methods: {
       
        //表格选择后回调事件
        selectionChange(selection) {
            this.selectionRows = selection;
        },
        //本地更新数据
        handleSaveSuccess(data, mode) {
            if (mode == "Add") {
                this.$refs.mytable.refresh();
            } else if (mode == "Edit") {
                this.$refs.mytable.refresh();
            }
        },
        async opBindData() {
            this.$refs.mytable.clearSort();
            this.$refs.mytable.getData();
        },
        resetSearch() {
            this.queryList={};
        },
        async initOptions() {
            try {
                var returnValue = await this.$API.auth.PostProcessApi.post(
                    "base-dictionary/options",
                    { Codes: ["AfterOrderStatus","AfterOrderType"] }
                );
                if (returnValue.status == 200) {
                    console.log("returnValue",returnValue);
					this.optionsStatus=returnValue.response.find(p=>p.code=="AfterOrderStatus").optionsDetails;
                    this.optionsAfterOrderType=returnValue.response.find(p=>p.code=="AfterOrderType").optionsDetails;
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }

            try {
					var returnValue = await this.$API.auth.PostProcessApi.post(
						"material-type/tree",
						{ status: 1 }
					);
					if (returnValue.status == 200) {
						this.materialTypeTree = returnValue.response;
					} else {
						this.$message.error("操作失败:" + returnValue.msg);
					}
				} catch (error) {
					this.loading = false;
					return false;
				}
        },
    },
    async mounted() {
        this.orgType = tool.data.get("USER_INFO").AccountType;
        await this.initOptions();
        await this.opBindData();
    },
};
</script>
